#include "ttree_declaration.h"

extern "C" {

#include <stddef.h>
#include <string.h>
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/alloc.h>
#include <caml/fail.h>
#include <caml/callback.h>
#ifdef Custom_tag
#include <caml/custom.h>
#include <caml/bigarray.h>
#endif
#include <caml/camlidlruntime.h>

value camlidl_c2ml_$(TA_DECL)_struct_ttree_decl (struct ttree_decl_$(TA_DECL) * _c1, camlidl_ctx _ctx);

void *get_ttree_$(TA_DECL)(const char* file_name,const char*tree_name);
long long n_of_ttree_$(TA_DECL)(void*t);
void fill_$(TA_DECL)(void *t, long long n);

value init_ttree_$(TA_DECL)(value file,value name)
{
  char *file_name = String_val(file);
  char *ttree_name = String_val(name);
  void *t_ = get_ttree_$(TA_DECL) (file_name,ttree_name);
//  return Val_string ( get_ttree (file_name,ttree_name) );
  return (value)(t_);
}
value get_n_$(TA_DECL)(value ttree)
{
  void *t = String_val(ttree);
  return copy_int64(n_of_ttree_$(TA_DECL)(t));
}
//value fill_event(value number,value ttree,value ocaml_record)
//{
//  void *t = String_val(ttree);
//  long long num = Int64_val(number);
//  fill(t,num);
//  return Val_unit;
//}
//value fill_ocaml_rec(value com_rec, value tree_)
//{
//void *t_ = (void*) tree_;
//}
struct camlidl_ctx_struct _ctxs_$(TA_DECL) = { CAMLIDL_TRANSIENT, NULL };
camlidl_ctx _ctx_$(TA_DECL) = &_ctxs_$(TA_DECL);

value get_event_$(TA_DECL) (value number,value ttree)
{
  void *t = String_val(ttree);
  long long num = Int64_val(number);
  fill_$(TA_DECL)(t,num);
//  return camlidl_c2ml_$(TA_DECL)_struct_$(TA_DECL)((struct ttree_decl*)t,_ctx);
  return camlidl_c2ml_$(TA_DECL)_struct_ttree_decl((struct ttree_decl_$(TA_DECL) *)t,_ctx_$(TA_DECL));
}
}
